package com.csdj.controller.sy;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.csdj.common.utils.ResponseResult;
import com.csdj.pojo.SyArea;
import com.csdj.service.SyAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 涵哥
 * @date 2023-08-24 14:38
 *  抄表辖区
 */
@RestController
@RequestMapping("/sy/area")
public class SystemAreaController {

    @Autowired
    private SyAreaService syAreaService;

    /**
     * 抄表辖区设置的列表
     * @return
     */
    @GetMapping
    public ResponseResult list(){
        List<SyArea> list = syAreaService.list(Wrappers.<SyArea>lambdaQuery().eq(SyArea::getDisabled,0)
                .orderByDesc(SyArea::getId));
        return ResponseResult.okResult(list);
    }

    /**
     * 新增
     * @param syArea
     * @return
     */
    @PostMapping
    public ResponseResult add(@RequestBody SyArea syArea){
        syArea.setDisabled(0);
        return ResponseResult.okResult(syAreaService.save(syArea));

    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public ResponseResult remove(@PathVariable Integer id){
        return ResponseResult.okResult(syAreaService.removeById(id));
    }

    /**
     * 根据id查找
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ResponseResult getOne(@PathVariable Integer id){
        return ResponseResult.okResult(syAreaService.getById(id));
    }

    /**
     * 修改
     * @param syArea
     * @return
     */
    @PutMapping
    public ResponseResult update(@RequestBody SyArea syArea){
        return ResponseResult.okResult(syAreaService.updateById(syArea));
    }
}
